#include <iostream>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <cassert>
#include <cstring>
#define PipeName "./Named_pipe"

int main()
{
    umask(0);
    mkfifo(PipeName, 0666);
    //若读端未打开会在此堵塞
    int fd = open(PipeName, O_WRONLY);
    char buffer[1024];
    while (true)
    {
        std::cout << "请输入你要发送的信息: "; 
        fgets(buffer,sizeof(buffer) - 1,stdin);
        buffer[strlen(buffer) - 1] = 0;
        write(fd, buffer, strlen(buffer));
        std::cout << "发送成功" << std::endl;
    }
    close(fd);
    return 0;
}